<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        var arr = [-1,-100,3,99];
        var k = 2;
        var rotate = function(nums, k) {
            while(k--){
                for (let i=nums.length;i>0;i--){
                    nums[i] = nums[i-1];
                }
                nums[0] = nums[nums.length-1];
                nums.pop();
            }
            return nums;
        };
        console.log(rotate(arr, k));
    </script>
</body>
</html>